// ========题目1================
require('./task01.js')

// ========题目2================
require('./task02.js')

// ===== 题目3===========
require('./task03.js')

//===== 题目4===========
const MyPromise = require('./task04.js');
//======== promise resolve =========
const p1 = new MyPromise((resolve, reject) => {
    resolve("success 01");
});
p1.then((value) => {
    console.log(value);
});

const p2 = new MyPromise((resolve, reject) => {
    setTimeout(() => {
        resolve("success 02");
    }, 1000);
});
p2.then((value) => {
    console.log(value);
    return "success 03"
}).then(console.log);

//======== promise reject =========
const p3 = new MyPromise((resolve, reject) => {
    reject("reject 01");
});
p3.catch((value) => {
    console.log(value);
});

const p4 = new MyPromise((resolve, reject) => {
    setTimeout(() => {
        reject("reject 02");
    }, 1000);
});
p4.catch((value) => {
    console.log(value);
    return "reject 03"
}).then(console.log).finally(() => {
    console.log("finally 04");
});

//======== promise all =========
let s1 = new MyPromise((resolve, reject) => {
    setTimeout(() => {
        resolve("promise all 1000");
    }, 1000);
});
let s2 = new MyPromise((resolve, reject) => {
    setTimeout(() => {
        resolve("promise all 500");
    }, 500);
})

MyPromise.all([s1, s2]).then((res) => { console.log(res) });

//======== promise race =========
let r1 = new MyPromise((resolve, reject) => {
    setTimeout(() => {
        resolve("promise race 1000");
    }, 1000);
});
let r2 = new MyPromise((resolve, reject) => {
    setTimeout(() => {
        resolve("promise race 500");
    }, 500);
})

MyPromise.race([r1, r2]).then((res) => { console.log(res) });
